using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using webapp4U.BOL;

namespace webapp4U.UI.Controls
{
    public partial class Contact : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btSend_Click(object sender, EventArgs e)
        {
            webapp4U.BOL.Contact obj = new webapp4U.BOL.Contact();
            obj.ContactID = 0;
            obj.CateID = 1; // 1 la Cate cua lien he
            obj.FullName = txtFullName.Text;
            obj.Address = txtAddress.Text;
            obj.Tel = txtTel.Text;
            obj.Email = txtEmail.Text;
            obj.Title = txtTitle.Text;
            obj.Content = txtContent.Text;
            obj.AddedDate = DateTime.Now;
            webapp4U.BOL.Contact.Insert(obj);

            PanelMsg.Visible = true;
            //lblMsg.Text = "Thank you! Your message has been sent successfully!";
            lblMsg.Text = ResourceManager.GetString("Contact_SendSuccessfully");

            ContactSetting contact = ContactSetting.GetContactSettingByID(1);
            string EmailTo = contact.Email;
            
            // goi email cho admin website
            SendMail sendmail = new SendMail();
            sendmail.MailServer = ConfigurationManager.AppSettings["SmtpServer"].ToString();
            sendmail.MailFrom = ConfigurationManager.AppSettings["EmailFrom"].ToString();
            sendmail.MailTo = EmailTo;
            sendmail.Subject = "Thu lien he duoc goi tu website: " +
                ConfigurationManager.AppSettings["Domain"].ToString();

            // noi dung can goi
            StringBuilder strBody = new StringBuilder(string.Empty);
            strBody.AppendLine("<br>");
            strBody.Append("<br> Full Name: " + obj.FullName);
            strBody.AppendLine("<br>");
            strBody.Append("<br> Email: " + obj.Email);
            strBody.AppendLine("<br>");
            strBody.Append("<br> Phone: " + obj.Tel);
            strBody.AppendLine("<br>");
            strBody.AppendLine("<br>");
            strBody.Append("<br> Title: " + obj.Title);
            strBody.AppendLine("<br>");
            strBody.Append(obj.Title);
            sendmail.Body = strBody.ToString();
            SendMail.Send(sendmail);

            // xoa sach form
            this.Form_Clear();

        }

        protected void Form_Clear()
        {
            txtFullName.Text = "";
            txtAddress.Text = "";
            txtTel.Text = "";
            txtEmail.Text = "";
            txtTitle.Text = "";
            txtContent.Text = "";
        }

    }
}